Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

proxy-bind

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proxy-bind

foobar.fn.bind(foobar) -> bind(foobar).fn

  • 1.2.2
  • next
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
68
increased by3.03%
Maintainers
1
Weekly downloads
 
Created
Source

proxy-bind

npm version actions codecov

tl;dr

from

const fn = foobar.fn.bind(foobar);

to

const { fn } = bind(foobar);

Install

npm install proxy-bind

Import

import { bind, bond } from 'proxy-bind';

.

import { bind, bond } from 'https://deno.land/x/proxy_bind/mod.ts';

.

const { bind, bond } = require('proxy-bind');

or

<script type="module">
    import { bind, bond } from 'https://cdn.jsdelivr.net/npm/proxy-bind@1.x/index.mjs';
</script>

.

<script type="javascript">
    (async () => {
        const { bind, bond } = await import('https://cdn.jsdelivr.net/npm/proxy-bind@1.x/index.mjs');
    })();
</script>

the bond is only an alias to avoid naming conflict, just in case.

Example

"point-free" ish

import { bind } from 'proxy-bind';

const { push, join } = bind([ 1, 2, 3 ]);

push(4);

console.log(join('-'));  // 1-2-3-4
import { bind } from 'proxy-bind';

const { resolve } = bind(Promise);

console.log(await resolve(42));  // 42
console.log(await resolve('foobar'));  // foobar

bind this

import { bind } from 'proxy-bind';

const me = {

    name: 'foo',

    greet (you) {
        return `Hi ${ you }, this is ${ this.name }.`;
    },

};

const { greet } = bind(me);

console.log(greet('bar'));  // Hi bar, this is foo.

mirror helper

import { mirror } from 'proxy-bind';

const [ list, { push } ] = mirror([ 1, 2, 3 ]);

push(4);

console.log(list);  // [1, 2, 3, 4]

Methodology

It uses ES6 Proxy to bridge function calls via Function.prototype.bind.

Caveat

  • Doesn't work on primitive types:
    • don't bind(5)
    • do bind(new Number(5))

License

the MIT

Keywords

FAQs

Package last updated on 09 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc